This question already has answers here:
Browsers does not reflects updates in the code [closed]
(12 answers)
Closed 2 years ago.
I have a simple form where users can register, and after submiting I want to work with the values to check everything is fine, the problem is that I cannot get some values.
This is the form in index.php:
<form class="form-detail" action="correcto.php" method="post" id="myform">
<select name="personaEmpresa" id="personaEmpresa">
<option class="option" value="empresa">Soy una empresa</option>
<option class="option" value="persona">Soy una persona</option>
</select>
<input type="text" name="first_name" id="first_name" class="input-text" placeholder="Nombre" required>
<input type="text" name="last_name" id="last_name" class="input-text" placeholder="Apellidos" required>
</form>
I have reduced the size of the form to be more concrete. Once I submit the form and go to correcto.php, I can perfectly work with "first_name" and "second_name" but for some reason I am not able to get the value from "personaEmpresa"
This is the code on correcto.php:
<?php
//I cannot get the value from this one
echo $personaEmpresa = $_POST["personaEmpresa"];
echo "<br>";
echo $nombre = $_POST["first_name"];
echo "<br>";
echo $apellidos = $_POST["last_name"];
Thank you all very much!
Did you put a submit type input into the form?
<form class="form-detail" action="correcto.php" method="post" id="myform">
<select name="personaEmpresa" id="personaEmpresa">
<option class="option" value="empresa">Soy una empresa</option>
<option class="option" value="persona">Soy una persona</option>
</select>
<input type="text" name="first_name" id="first_name" class="input-text" placeholder="Nombre" required>
<input type="text" name="last_name" id="last_name" class="input-text" placeholder="Apellidos" required>
<input type="submit" value="">
Finally the error was just that the cache of the browser needed to be updated. You can use classic cache killer in Chrome or Firefox to solve this.
Related
I have the following form, how can i get the data from multiple[] arrays in the form and combine them into 3 data sets eg name[], quantity[], unit[]
<input type="text" name="name[]" class="form-control" placeholder="Name" />
<input type="text" name="name[]" class="form-control" placeholder="Name" />
<input type="text" name="name[]" class="form-control" placeholder="Name" />
<input type="text" name="quantity[]" class="form-control" />
<input type="text" name="quantity[]" class="form-control" />
<input type="text" name="quantity[]" class="form-control" />
<select name="unit[]" >
<option value="">--Unit--</option>
<option value="g">g</option>
</select>
<select name="unit[]" >
<option value="">--Unit--</option>
<option value="g">g</option>
</select>
<select name="unit[]" >
<option value="">--Unit--</option>
<option value="g">g</option>
</select>
The PHP Manual at http://php.net/manual/en/tutorial.forms.php answers your question.
Example #1 A simple HTML form
>
>
>
> <form action="action.php" method="post">
> <p>Your name: <input type="text" name="name" /></p>
> <p>Your age: <input type="text" name="age" /></p>
> <p><input type="submit" /></p>
> </form>
>
>
>
There is nothing special about this form. It is a straight HTML form
with no special tags of any kind. When the user fills in this form and
hits the submit button, the action.php page is called. In this file
you would write something like this:
Example #2 Printing data from our form
>
> Hi <?php echo htmlspecialchars($_POST['name']); ?>.
> You are <?php echo (int)$_POST['age']; ?> years old.
>
>
A sample output of this script may be:
Hi Joe. You are 22 years old.
Apart from the htmlspecialchars() and (int) parts, it should be
obvious what this does.
Do var_dump($_POST) to view all results.
in $_POST['name'] (or quantity or unit) u have an array with 3 results.
why am I getting undefined index's with my form is it because of the encoding type I am using, if so what can I do to fix this to properly post my variables
<form enctype="multipart/form-data" name="pmForm" id="pmForm" method="post" action="personalspage.php"><br>
<b>Age</b> <input type="text" name="age" id="age" cols="4"><br><br>
<b>University</b> <select name="university" id="university" onfocus="emptyElement('status')">
<option disabled selected>select one...</option>
<option value="Algoma">Algoma University</option>
<option value="york">York University</option>
</select><br><br>
<b>Headline</b> <input type="text" name="headline" id="headline"><br><br>
<b>Message</b> <textarea name="message" id="message" rows="6" cols="50"></textarea><br><br>
<b>Add a picture</b> <input type="file" name="photo" id="photo" accept="image/*"><br><br>
<input type="hidden" name="mysex" id="mysex" value="<?php echo $_POST["mysex"]; ?>">
<input type="hidden" name="lookingfor" id="lookingfor" value="<?php echo $_POST["lookingfor"]; ?>">
<center><input type="submit" name="adSubmit" id="adSubmit" value="Post It"></center>
</form>
I know that the variables being posted from say page1 to this form are coming through because I have an if statement with an isset() for the variables making it header to another page if there not set. this form code is from page2
im using this code on page3 to recieve the form data
$mysex = $_POST['mysex'];
$lookingfor = $_POST['lookingfor'];
$uni = $_POST['university'];
So when I post all the variable from this form to another page I get
Notice: Undefined index: mysex in C:\xampp\htdocs\Website\personalspage.php on line 4
Notice: Undefined index: lookingfor in C:\xampp\htdocs\Website\personalspage.php on line 5
Notice: Undefined index: university in C:\xampp\htdocs\Website\personalspage.php on line 6
I double checked and made sure that all my methods are using post, the only thing I can think of why this isnt working is because of some sort of combination of echoing input values and the enctype. If anyone could help me out it would be greatly appreciated.
Undefined variable university means you didnt select any options to fix that you can set any of the ptions to selected and for hidden variables problem is value is not there. fixed code is here
<form enctype="multipart/form-data" name="pmForm" id="pmForm" method="post" action="personalspage.php"><br>
<b>Age</b> <input type="text" name="age" id="age" cols="4"><br><br>
<b>University</b> <select name="university" id="university" onfocus="emptyElement('status')">
<option disabled selected value="" selected>select one...</option>
<option value="Algoma">Algoma University</option>
<option value="york">York University</option>
</select><br><br>
<b>Headline</b> <input type="text" name="headline" id="headline"><br><br>
<b>Message</b> <textarea name="message" id="message" rows="6" cols="50"></textarea><br><br>
<b>Add a picture</b> <input type="file" name="photo" id="photo" accept="image/*"><br><br>
<input type="hidden" name="mysex" id="mysex" value="<?php if(isset($_POST["mysex"])) echo $_POST["mysex"];else echo ""; ?>">
<input type="hidden" name="lookingfor" id="lookingfor" value="<?php if(isset($_POST["lookingfor"]))echo $_POST["lookingfor"];else echo ""; ?>">
<center><input type="submit" name="adSubmit" id="adSubmit" value="Post It"></center>
</form>
I Have Any Two option
First:
error_reporting(0);
Second:
<input type="hidden" name="mysex" id="mysex"
value="<?php if(isset($_POST["mysex"])){ echo $_POST["mysex"]; }?>">
<input type="hidden" name="lookingfor" id="lookingfor"
value="<?php if(isset($_POST["lookingfor"])){ echo $_POST["lookingfor"]; }?>">
I have been asked to update a contact form, i always leave action blank(action="") in any forms i have worked on before. I have been sent the following form as seen below. When the form is submitted, it is sent to the url, which is a blank screen. Has anyone implemented a salesForce contact form before ?
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<input type=hidden name="oid" value="00D200000005wgb">
<input type=hidden name="retURL" value="http://"> <!-- add URL of completed page here
-->
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<label for="email">Email Address</label><input id="email" maxlength="80" name="email" size="20" type="text" /><br>
<label for="phone">Phone</label><input id="phone" maxlength="40" name="phone" size="20" type="text" /><br>
<select id="country" name="country" title="country">
<option value="London">London</option>
<option value="Midlands">Midlands</option>
<option value="North England">North England</option>
<option value="South England">South England</option>
<option value="Wales">Wales</option>
<option value="Scotland">Scotland</option>
<option value="Northern Ireland">Northern Ireland</option>
</select><br>
<textarea id="00N200000016Kk5" name="00N200000016Kk5" rows="4" type="text" wrap="soft"></textarea><br>
<!-- Below 3 fields are hidden -->
<select id="recordType" name="recordType" style="display:none;">
<option value="012w0000000QCbe">Prospect UK</option></select>
<select id="00N20000001L8Pi" name="00N20000001L8Pi" title="Web Source" style="display:none;"><option value="Download Whitepapers UK">Download Whitepapers UK</option> </select>
<select id="lead_source" name="lead_source" style="display:none;">
<option value="Download Whitepapers UK">Download Whitepapers UK</option></select>
<input type="submit" name="submit">
</form>
The action attribute of a <form> is basically a redirect for the form that sends the POST or GET data along with it.
If action is left blank, it redirects to the current URL, thus "refreshes".
If action is a link beginning with http:// or https://, the form sends the $_POST / $_GET request to the full page link.
If action is set to a link not beginning with http:// nor https://, the link set in the action is added to the current sub-directory in the same way a php include works.
Therefore, this in your code:
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
Will send a POST request to https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've got a form with 6 inputs of different types (select, radio, text...). When I debug with Xdebugg I can see the values in $_POST variable,
I've decided to add other input but they arent posted : when I look at $_POST variable, I just have the first 6 values.
Here's a part of my form :
edit : i've copy/paste the code this time. My boss told me to not send the real code, that's why I've send a fake code but i really need some help so here's the real one.
<div id="modifierUser" class="divAdmin">
<form id="modifierUserForm" name="modifier_user"action="includes/inc_adminModifierUser.php">
<fieldset>
<legend>
<img src="img/bulle_48.png" alt="bulle" title="bulle" />
<h3>Modifier le compte</h3><br />
</legend>
<!-- the field i've tried to add -->
<label class ="labelEmail" for="idmembre">ID du membre </label>
<input id="idmembre" name="idmembre" size="35" class="required"/>
<!-- -->
<label class ="labelEmail" for="pseudo">Utilisateur </label>
<input id="pseudo" name="pseudo" size="35" class="required"/>
<label class ="labelEmail" for="anneeNaiss">Année de naissance </label>
<input id="anneeNaiss" name="anneeNaiss" placeholder="e.g : 1984" size="35" class="required" maxlength="4" value="" />
<label class ="labelEmail" for="email">Email </label>
<input id="mail" type="email" name="email" size="35" class="email" value="" maxlength="50"/>
<label class ="labelEmail" for="telephone">Téléphone</label>
<input id="telephone" type="tel" name="telephone" size="35" class="required" value="" maxlength="10" />
<label class ="labelEmail"> Masquer numéro dans l'annonce</label>
<input type="radio" name="masquerTel" value="oui" id="oui" checked="checked" />
<span>Oui</span>
<input type="radio" name="masquerTel" value="non" id="non" /><span>Non</span>
<label class ="labelEmail" for="region">Région</label>
<select id="region" name="region" size="1" class="required" style="width:180px"
<option value="Aquitaine" selected="selected" >Aquitaine </option>
<option value="Alsace">Alsace </option>
<!-- There's many options there-->
</select>
<input type="submit" name="enregistrer" value="Enregistrer les modifications" size="35"/>
<input type="button" name="annuler" class="annuler" value="ANNULER" />
</fieldset>
</form>
</div><!--fin modifierUser-->
variable i can see :
$_POST['pseudo']
$_POST['anneNaiss']
$_POST['email']
$_POST['telephone']
$_POST['masquerTel']
$_POST['region']
i'll always have $_POST[6]in xdebug, no matter how many input i add. But i tried to suppress one of 6 above input and i got $_POST[5].
The one I need to see
$_POST['idmembre']
Sorry for wasting your time
It looks as if the values aren't being posted because you've mispelt "action", calling it "ation" in the form element starting tag. <form>.
Because of this your form will be posting to the same page it's output in, rather than the page you're trying to POST the data to.
The first line of your code should look like this instead:
<form id="modifyUserForm" name="modify_user" action="includes/inc_adminModifyUser.php">
it seems that you have an extra double quote in your code so thats normal you HTML code does not render correctly:
<input id="inp_realname" name="realname" size="35" "/>
should be:
<input id="inp_realname" name="realname" size="35" />
HTML FORM
<form class="form" method="post" action="process.php">
<h4 class="form-heading">Please New Enter Customer Information</h4>
<label for="inital">Inital:</label>
<select id="inital" name="inital" required="required">
<option value="mr">Mr</option>
<option value="ms">Ms</option>
<option value="mrs">Mrs</option>
<option value="prof">Prof</option>
<option value="dr">Dr</option>
</select>
<label for="firstname">First Name:</label>
<input type="text" placeholder="First Name" name="firstname" required="required" >
<label for="lastname">last Name:</label>
<input type="text" placeholder="Last Name" name="lastname" required="required">
<label for="mobile">Mobile:</label>
<input type="tel" placeholder="Mobile" name="mobile" required="required">
<label for="landline">Landline:</label>
<input type="tel" placeholder="Landline" name="landline">
<label for="email">Email:</label>
<input type="email" placeholder="Email" name="email" required="required">
<label for="address">Address:</label>
<input type="text" placeholder="Address" name="address" required="required">
<label for="postocde">Postal Code:</label>
<input type="text" placeholder="Post Code" name="postcode">
<label for="accessibility">Accessibility:</label>
<input type="text" placeholder="Accessibility Needs" name="accessibility" value="">
<button class="btn btn-large btn-primary" type="submit">Enter</button>
process.php
<? php
require( '../connect_db.php' ) ;
$inital = $sql->real_escape_string($_POST[inital]);
$firstname = $sql->real_escape_string($_POST[firstname]);
$lastname = $sql->real_escape_string($_POST[lastname]);
$mobile = $sql->real_escape_string($_POST[mobile]);
$landline = $sql->real_escape_string($_POST[landline]);
$email = $sql->real_escape_string($_POST[email]);
$address = $sql->real_escape_string($_POST[address]);
$postcode = $sql->real_escape_string($_POST[postcode]);
$accessibility = $sql->real_escape_string($_POST[accessibility]);
$query = "INSERT INTO `customer` (inital, firstname, lastname, mobile, landline, email, address, postcode, accessibility) VALUES ('$inital','$firstname', '$lastname','$mobile','$landline','$email','$address','$postcode','$accessibility')";
/* execute the query, nice and simple */
$sql->query($query) or die($query.'<br />'.$sql->error);
?>
I have tried alternatives too but to no satisfaction like not including $inital =($_POST[inital]); Instead putting right into INSERT INTO section but that still does not help either.
It either prints out the whole code on screen or blank. I've looked at similar problems on here and on forums all them seem to present the issue differently and when i change it suit the so called answer it still does not work!
My other page that lists all the tables using the following connection required statment works works fine so there is no problem with connection to the database but at this moment just cannot insert content. Grr
Two problems:
change <? php to <?php
and then add quotes to your post data values. $_POST[inital] to $_POST['inital']
and for your information i would do isset($_POST['value']) ? $_POST['value'] : '';
you still need to check post value before using it.
Check the <? php tag. it should be <?php