How do I pass hidden information about a form?
<form action="index.php" method="post">
<textarea rows="2" cols="30" NAME="com" >
</textarea>
<input type="submit" name="com_submit" value="com" />
</form>
I need see that the comment is passed for which type of post so I need to pass the value of variable $type also by this form so how should I do that?
I am a beginner so i am sorry if i am asking any stupid question?
Use a hidden field:
<input type="hidden" name="form_type" value="theFormType" />
The user will not see hidden inputs on the form.
If the value of the hidden form comes from php, you can use this:
<input type="hidden" name="form_type" value="<?php echo $type ?>" />
if i understand correctly you want to use the hidden input
hidden input a great summary from w3schools
Related
I have 2 forms named form1 and form2 in a single php page.form1 contains one text box.form2 contains two text boxes with a submit button.I want to validate all the textboxes when ever submit button pressed.But I cannot access the textbox value in form 1.My code is given below.
<html><body>
<form name=form1 method=POST>
<input type=text name=f1_t1>
</form>
<form name=form2 method=POST>
<input type=text name=f2_t1>
<input type=submit name=sub1>
</form></body></html>
<?php
if(isset($_POST['sub1']))
{
$name=$_POST['f1_t1'];
echo $name;}
?>
this code error as undefined variable f1_t1.Can anyone help please?
I suggest putting everything in a single form, and displaying/hiding sections of it as necessary (for example, with jQuery and CSS).
As an example, you could do this:
<form>
<div id="part1">
<input name="t1" type="radio" value="v1" />
<input name="t1" type="radio" value="v2" />
</div>
<div id="part2" style="display: none;">
<input name="t2" type="text" />
<input type="submit" />
</div>
</form>
Only the fields in one form are submitted.
If for some reason you need to get the falues from a second form, you need to do that before posting, that is, on the client side. You could for example use javaScript to read the value of the field from the first form, write it to a hidden field in the second, and then post that to the server.
I have this javascript line
<script type="text/javascript">document.write(top.location);</script>
and this code
<form action="rating.php" method="post">
<input type="hidden" name="url" value="xxxx" />
<input type="submit" />
</form>
<?
echo $_POST["url"];
?>
Please, How i can add the value of javascript (xxx) in the hidden field?
Also does it possible to let <input type="submit" />have automatic submit ?
Thanks
Do you mean this, in order to feed the hidden field?
<input type="hidden" name="url" value="<? echo $_POST["url"]; ?>" />
Regarding submit, you can use javascript to handle the submit event:
If you add the attribute name="FORMNAME" inside the <form ... > tag, you can use:
document.FORMNAME.submit();
for submitting the form, without using the submit button.
In order to feed a hidden field through javascript, use:
document.FORMNAME.url.value = top.location;
I use a form to send some data to my welcome.php file:
<form action="welcome.php" method="post">
Name: <input type="text" name="txt" />
<input type="submit" />
</form>
But, is it possible to send other variables instead of just form element values? Let's say I want to send the number 100 to welcome.php as well.
You would probably use a hidden input:
<form action="welcome.php" method="post">
<input type="hidden" name="myNumber" value="100" />
Name: <input type="text" name="txt" />
<input type="submit" />
</form>
That would send the myNumber $_POST value to welcome.php.
Modifying the action like this: welcome.php?myNumber=100 would mean that you are sending a GET variable in addition to the POST variables inside the form.
NOTE: You could theoretically use both, but I believe that would only put the $_POST value in the $_REQUEST object. You should confirm that before relying on that behavior.
If I understand correctly:
<input type="hidden" name="myNumber" value="100" />
Right?
other then hidden fields or form element you can use AJAX to send other variables into the post.
where you can pass url with your new variables other than form fields.
Thanks.
You can hardcode that into your action:
<form action="welcome.php?number=100" method="post">
This should work:
<form action="welcome.php?number=100" method="post"/>
or use a hidden form input
<input type="hidden" name="number" value="100" />
You can use html hidden field or store the value what you want in session or cookie varible
I have a form with a submit button and a handler that stores data in the database. Problem is when the form is submitted, all data is cleared from the input fields. Is there a way to still show them after submit? What changes do I need to make to my form_submit function?
function mymodule_form_submit($form, &$form_state) {
//how to retain the input in the form
}
I'm looking for the most "drupalish" way to get this done?
As indicated by this previous StackOverflow question you can accomplish this with $form_state['storage'] and $form_state['rebuild'].
You can access the data using $_REQUEST['form_variable_name'] where form_variable_name is the name of the html input tag.
You then need to render the page back putting this value into the input tags value field.
<form method="POST" action="/account/contactdetails/">
<div>
<label>First name:</label>
<input type="text" name="firstname" value="<?php echo $_REQUEST['firstname']; ?>" />
</div>
<div>
<label>Last name:</label>
<input type="text" name="lastname" value="<?php echo $_REQUEST['lastname']; ?>" />
</div>
<input type="submit" value="Save" />
</form>
I'm trying to build a form using php & jquery, but I'm a little confused as to what to do with the jquery portion of it...
Basically, when the user submits the first form, I want to direct them to the "next step" form, but I want to retain the values submitted from the first one in a hidden input field...
If someone can either show me how or point me to a good tutorial, I'd appreciate it...
I don't have any of the php or jquery yet, and this is just a simplified version of the html markup...
//first.php
<form name="form1" method="post" action="second.php">
<input type="text" name="name" value="" />Name
<input type="submit" name="step1" value="Next" />
</form>
//second.php
<form name="form2" method="post" action="process.php">
<input type="hidden" name="name" value="{$_POST['name']}" />
<input type="text" name="message" value="" />message
<input type="submit" name="step2" value="Finish" />
</form>
<input type="hidden" name="name" value="{$_POST['name']}" />
should be,
<input type="hidden" name="name" value="<?php echo $_POST['name']}; ?>" />
and also sanitize the input, if you want
I don't no if there is a better way to do that.
But, when I need to do such thing, I do in this way:
<script>
<?php
foreach($_POST as $key => $valule)
{
echo "$('$key').val('$value')";
}
?>
</script>
So, in your nextstep file, all you'll need to do is set up the hidden fields and then just loop through the post vars and set each one via jquery.