PHP Formatting URL within a Form Action - php

I would like to add the ID of a User to the form action as a URL.
For Example view_member.php?id=2
Can somebody possible show me the correct way to format PHP code in the form action below where I can include the id as $recptid
$recptid = $_GET['id'];
I have tried
<form action="<?phpview_member.php?id=$recptid?>" method="post">
I would like to be able to add a link but my formatting is wrong
// insert php code as URL in the form action the a submit is pressed
<form action="<?php?>" method="post">
</form>
Thanks in advance for any help

try this,
<form action="<?php echo "view_member.php?id=".$recptid; ?>" method="post">
i hope it will be helpful.

Related

Keeping Current URL after form submit PHP

Say I have e.g: (foo.com/index.php?a=1) and a form on it to submit data, but when the submit is hit the url refreshes and it gets rid of the values from the attached.
How do I make the url on my page to stay same as before even when the sumbit button is clicked.
Thanks
Like this: action="yourpage.php?var1=value1&var2=value2". You can get these with PHP like so: $var1 = $_GET['var1'].
Example:
<form method="post" action="yourpage.php?var1=value1&var2=value2">
[...]
</form>
You can do this to add existing variables into the url:
<form method="post" action="yourpage.php?var1=<?php echo $_POST['var1'];?>&var2=<?php echo $_POST['var2'];?>">
[...]
</form>
<!-- Output:
<form method="post" action="yourpage.php?var1=value1&var2=value2">
[...]
</form>
-->
Change the form action in the HTML to post. i.e.:
<form action="..." method="post">
Assuming its a get at the moment. Then set action to your URL

Issues in working of PHP form submit with GET data

I am working with PHP forms.
The opening form tag looks like this:
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
This generated the following HTML:
<form name="adv_search_form" action="index.php?&rel=common_listing&module=company&sort_option=&search_option=&show_max_row=15" method="GET">
When I submit this form, I land on a URL:
http://localhost/projectcode12may2014/ampanel/index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
But what I want is that
?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit
should be appended to the action URL on the landing page. Can anyone suggest any good method for doing this?
Thanks in advance.
If you are using method="get" the parameters in action are overwritten. Only what is in the from will be transmitted.
You need to add hidden fields for all these values. For example:
<input type="hidden" name="module" value="company" />
That is your from data.
You have method="get" in your form tag. This means that the form data is concatinated to the URL. Use method="post" to have send form data as a POST request and keep your URI clean.
So change this line
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">
to this
<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="post">
Then you can access your form data in PHP with the global $_POST var which holds an array with the submitted data.
This is a normal behavior. Using GET method discard all parameters specified directly in action attribute.
Use POST method instead or move parameters from action attribute of the form to input fields with type="hidden".

File extension added after form submit

Let's say I have a form on my website homepage: www.mysite.com
Now, the form tag looks like this:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
</form>
When that form submits, it does everything it's suppose to. But it also reloads the page with the full filename and extension. So the user will now find the URL in the address bar is: www.mysite/index.php
Is there a way to make the form fire to the same page without adding this extension?
There may be situations where the form is as an include in a footer, so I cann't be specific about the page the form needs to fire to, hense the PHP_SELF code.
That's because $_SERVER['PHP_SELF'] refers to the actual filename of the current script.
Try this:
<form action="" method="post">
An empty action will post back to the current URL.
Try setting the action to #:
<form action="#" method="post">
...
</form>
The # refers to the current page.
Try changing action to #, this post to the current page.
Edit: Mike beat me to it.
Edit 2: It looks like you can leave out the action all together and it will default to the same page.
Edit 3: Mike beat me to that one too.

html form action="." not submitting to self, but instead submitting to root directory

I have a form in one of my pages and I want to make it submit to the same page. I am doing this:
<form method="POST" action=".">
But when I submit the form it submits to the root directory of my site instead of to the same page the form is on.
I know that the form is being submitted because I tried temporarily changing the method to GET and when I submitted the form, the URL showed the get variables.
Why is the form not submitting to the current page?
If it's relevant, I'm using PHP with xampp.
Try this:
<form method="POST" action="">
This is what I do
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
I'm a newbie though so if Juampi's answer works too , I'd go with it.

CodeIgniter Form Action Url Variable

What would be the exact CodeIGniter format to the below form tag. Thanks
<form action="links/link1.php?view=one" method="post">
Will this work
echo form_open('links/link1.php?view=one');
That's right.
echo form_open('links/link1.php?view=one');
will create a form similar to this:
<form action="links/link1.php?view=one" method="post">
Hope this helps.

Categories