开发者

Can I include a forms value into the action redirect in php?

Is it possible in php to include a forms value into the action redirection?

For example:

<form method='POST' name='Select' action='customer.php?CID=xxxxx'>
<input type=text width='5' name='searchVal' />

where xxxxx is the value entered into the form.

I've tried a number of different ways and I'm just not figuring it out! (Still sort of new to php) Any help would be appreciated.

It was looking like I would have to use $_POST and $_GET. A little more information might be in order... customer.php displays a list of customers in order by ID, name, etc. The user currently clicks on the customer ID that they want to display the details for. I'm trying to add a box where they can just enter the customer number to get to the details quickly, but I still want to have the listing displayed. From what it is soundin开发者_如何学Gog like, I will have to do this as two separate programs...is that true?


How about this:

<form method='POST' name='Select' action='customer.php'>
<input type='hidden' value='xxxxx' name='CID' />
<input type=text width='5' name='searchVal' />
...
</form>

You are free to add as much hidden values as needed.

Note, that you can even use PHP-like array notation_

<input type='hidden' value='xxxxx' name='CID[1]' />
<input type='hidden' value='yyyyy' name='CID[2]' />

At the PHP-side, access those values using this syntax:

$_POST[ 'CID' ][ 1 ]
$_POST[ 'CID' ][ 2 ]

UPDATE-1

Ah, you want to use a user-entered values to the Action URL just before the form gets submitted?

In this case you need to use JavaScript. Access the DOM to change the Action URL.

But let me ask, why you need to post a form value additionally as a parameter of the Action URL?

UPDATE-2

You wrote: 'From what it is sounding like, I will have to do this as two separate programs...is that true?'

No, actually not. You can still use one customer.php which checks at its beginning, if it was called using a linked customer in the table element or a searched customer in the search field.

In other words: You don't need to prepare two scripts, but two forms for two purposes which call the same script customer.php.


You can include the required value in a hidden field in your form:

<input type="hidden" name="CID" value="xxxxx" />

The reason this is required is that you are submitting the form to your server via POST, but appending parameters to the URL requires submission via the GET method.


Not without a post to the server. The value in the form is filled in client-side, so it has to return to the server before you can add it to the action. (at least, if you want to use php).

You can either

  • add it after posting (might not be usefull)
  • use javascript
  • just not use the GET CID, but get it out of the POST in your customer.php script.


I got it finally! It's actually very simple!

In the body of the code I put this:

<form action='#_SELF' method='GET' name='Projected'>
<input type=text size=5 name='CID' value='' title='Enter Customer number to display' />
<a href='#' onclick='document.Projected.submit();' title='Enter Customer number to display'>Go</a>

And at the top of the code I just do a:

if (!isset($_GET['CID'])) { ...

It works exactly the way I wanted it to!

Thanks everyone for the help! I appreciate it! (And I'm learning more and more about PHP everyday!)


Im pretty sure you cant do that unfortunately

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜