I have a strange issue that I cannot get my head around.
I have the following form and when I click submit I do not GET or POST all fields in the form. Only two fields are being picked up being - isnew=true action=object &submit=Start
<form name="newOffer" action="/auth/dashboard" method="post">
<td><?php echo form_hidden('isnew', 'true');?><?php echo form_hidden('action', 'object');?><input type="text" id="newOfferItem" placeholder="Offer Free Item" class="input-xlarge"></td>
<td><input type="text" id="newOfferText" placeholder="Offer Description" class="input-xlarge" rel="tooltip" title="Description How to get free item"></td>
<td><input type="text" id="newOfferFreeOn" placeholder="Stamps for free item" class="input-xlarge" rel="tooltip" title="Number only. Ex. 5"></td>
<td><span class="label label-danger">Inactive</span></td>
<td><?php $attributes = 'class = "btn btn-success"'; echo form_submit('submit', 'Start', $attributes);?></td>
</form>
You need to add NAME attributes for each INPUT element - either instead of or in addition to the ID attributes.
e.g.
<form name="newOffer" action="/auth/dashboard" method="post">
<td>
<?php echo form_hidden('isnew', 'true');?>
<?php echo form_hidden('action', 'object');?>
<input type="text" NAME="newOfferItem" id="newOfferItem" placeholder="Offer Free Item" class="input-xlarge">
</td>
<td>
<input type="text" NAME="newOfferText" id="newOfferText" placeholder="Offer Description" class="input-xlarge" rel="tooltip" title="Description How to get free item">
</td>
<td>
<input type="text" NAME="newOfferFreeOn" id="newOfferFreeOn" placeholder="Stamps for free item" class="input-xlarge" rel="tooltip" title="Number only. Ex. 5">
</td>
<td>
<span class="label label-danger">Inactive</span>
</td>
<td>
<?php $attributes = 'class = "btn btn-success"'; echo form_submit('submit', 'Start', $attributes);?>
</td>
</form>
Always add a name attribute in input element.
Here is an example for you..
index.html
<form method="POST" action="process.php">
<input type="text" name="username" value="">
<input type="password" name="password" value="">
<input type="submit" name="submit" value="login">
</form>
process.php
<?php
// checking if submit is pressed
if (isset($_POST['submit'])) {
// assigning posted values
$username = $_POST['username'];
$password = $_POST['password'];
// testing
echo $username . "<br>";
echo $password;
}
?>
Related
I want to keep the data in a text box after submit and inserted into db.
even if i refresh the page data should not change or empty
here is my code
<tr class="form-field1">
<th valign="top" scope="row">
<label for="approved_admin"><?php _e('Collaboration Admin', 'custom_table_example')?></label>
</th>
<td>
<input id="approved_admin" name="approved_admin" type="email" value="<?php echo esc_attr($item['approved_admin'])?>"size="50" class="code" placeholder="<?php _e('Admin Email', 'custom_table_example')?>" required>
</td>
</tr>
if i do this data will be there if i reload empty text box will be shown.I need to make this readonly and onload same text should be there.
Form
<form id="form" method="POST">
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(basename(__FILE__))?>"/>
<?php /* NOTICE: here we storing id to determine will be item added or updated */ ?>
<input type="hidden" name="sid" value="<?php echo $item['sid'] ?>"/>
<div class="metabox-holder" id="poststuff">
<div id="post-body">
<div id="post-body-content">
<?php /* And here we call our custom meta box */ ?>
<?php do_meta_boxes('Settings', 'normal', $item); ?>
<input type="submit" value="<?php _e('Save', 'custom_table_example')?>" id="submit" class="button-primary" name="submit" / >
<input type="submit" value="<?php _e('Edit', '')?>" id="edit" class="button-primary" name="edit" / >
</div>
</div>
</div>
</form>
I tried doing
<input type="email" name="approved_admin" value="<?php if (isset($_POST['approved_admin'])) { echo $_POST['approved_admin']; } ?>">
and also
<input type="text" name="country" value="Norway" <?php isset($approved_admin) ? echo 'readonly' : ''; ?> >
You can save data after page reload a lot of ways like... Session , cookie, get , post. After this value get by isset and echo .
In your case Post method used..
Try this working fine all thing
<input type="text" name="country" value=" <?php echo isset($_POST['country']) ? $_POST['country'] : ''; ?>" <?php echo isset($_POST['country']) ? 'readonly' : ''; ?> >
You just put field name in isset();
You can use this syntax. Have a try for this.
<input type="text" id="to_date" name="to_date" class="form-control" placeholder="Enter End Date" value="<?php echo isset($_POST['to_date']) ? $_POST['to_date'] : '' ?>" />
The name of the input type has to be mentioned in the isset() condition.
I have a form page and when I submit this form all inputs are posting successfully except this one:
<input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()"
<?php if($this->data['kullanici_id']){echo 'readonly';} ?>
value="<?php echo $this->data['kullanici_id']?>">
But why?
-This is my .phtml file:
<html>
<head>
</head>
<body>
<form enctype="multipart/form-data" action="/admin/kaydet" method="post" onSubmit="javascript: beforeSubmit();">
<?php if(strlen($this->data['id'])):?>
<input type="hidden" name="id" value="<?php echo $this->data['id']?>">
<?php endif;?>
<font color="green"><h3>DÜZENLE</h3></font>
<img src="/foto/<?php echo $this->data['fotograf']?>" height="110" width="110" align="left" />
<table class="table">
<tr>
<td>T.C. Kimlik No.:</td>
<td><input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" <?php if($this->data['kullanici_id']){echo 'readonly';} ?> value="<?php echo $this->data['kullanici_id']?>"></td>
</tr>
<?php if(!strlen($this->data['id'])):?>
<tr>
<td>Parola:</td>
<td><input id="password2" class="form-control" type="password" name="parola" value="<?php echo $this->data['parola']?>"></td>
</tr>
<tr>
<td>Parola Tekrar:</td>
<td><input onchange="passwordCheck(this.value)" class="form-control" type="password" name="parola" value="<?php echo $this->data['parola']?>"></td>
</tr>
<?php endif; ?>
</table>
<td><button type="submit" class="btn btn-success btn-sm glyphicon glyphicon-floppy-disk">KAYDET</button> </td>
</form>
</body>
</html>
If I have an id; page looks like an edit member page, if I haven't; page will add a new member. In id="TC" input, if I edit a member, this input shouldn't change, so I add a readonly to solve this. But when I submit, input does not post.
Sorry about my bad English :D
Reason your field is not being submitted it is because its set to readonly.
Reason for this is 'If user cannot change the field there is no point of submitting it as value will always remain the same'.
One way to mitigate this behavior is to add hidden field with same name
<input type="hidden" name="kullanici_id" value="<?php echo $this->data['kullanici_id']?>"> />
<input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" <?php if($this->data['kullanici_id']){echo 'readonly';} ?> value="<?php echo $this->data['kullanici_id']?>" />
So, I am creating a simple form:
<tr>
<td>
<label for="FirstName">First Name <span class="req">*</span>
</label>
<br />
<input type="text" name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<tr>
<td>
<label for="LastName">Last Name <span class="req">*</span>
</label>
<br />
<input type="text" name="LastName" id="LastName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<input class="cat_button" type="submit" value="Submit" id="catwebformbutton" />
What I would like it to do is when the user click submit, it will take them to another page where those details will be confirmed, or simply shown to them. any ideas? or sample codes?
where the form ? I cant see any form in your code !
try create 2 php files
index.php file
<form action="next_page.php" method="post">
<table>
<tr>
<td>
<label for="FirstName">First Name <span class="req">*</span></label>
<br />
<input type="text" name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<tr>
<td>
<label for="LastName">Last Name <span class="req">*</span></label>
<br />
<input type="text" name="LastName" id="LastName" class="cat_textbox" maxlength="255" />
</td>
</tr>
</table>
<input class="cat_button" type="submit" value="Submit" id="catwebformbutton" />
</form>
next_page.php file
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
echo "first Name : ".$FirstName."<br>";
echo "last Name : ".$LastName."<br>";
you want to use form method post and action form to do action in other page ,
and post data in another page using $_POST[]
Good references may be helpful to learn these things :
about form method ->
http://www.w3schools.com/tags/att_form_method.asp
about form action ->
http://www.w3schools.com/tags/att_form_action.asp
about $_POST in php ->
http://php.net/manual/en/reserved.variables.post.php
OK so I have two different types of forms and I want to use one form to submit them both. I am using a auto-responder form for form1 fields= first, last and email. My second form is a contact me form fields= name. email and a body field. I am trying to use both these forms at one shot. I have a form that will post fields to each form (INDEX.PHP) the problem is I am not sure how to set up form one to post fields into form1 and form2 the way I want. I want to use the fields that match from form index.php to both the other forms (form1, form2). so name and email will go to both forms and the body field will go to form2. The main form will post first and last in the name field of form2....also as you can see from form 1 and 2 each form has a some sort of redirect page I need to work around.?
I have main form:
Index.php
<html>
<head>
<title>Main Form</title>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
First Name: <input type="text" name="first_name" value="<?php echo $first_name;?>">
<FONT><font color="red"> *</font>
<br>
Last Name: <input type="text" name="last_name" value="<?php echo $last_name;?>"> <FONT><font color="red"> *</font>
<br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<FONT><font color="red"> *</font>
<br><br><i><b>Copy and paste auction item name below.</b></i><br>
Product Name: <input type="text" name="product_Name" rows="1" cols="10">
<?php echo $product_Name;?><FONT><font color="red"> *</font>
<input type="Submit" value="Submit" name="submit"></input>
</form>
</body>
</html>
the above form was found on a website and was pretty close to what I want it to do but not exactly....
Form1
<?php session_start(); ?>
<html>
<head>
<title>autoresponder</title>
</head>
<body>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;">
<tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://blog.jeremyahenry.com/mailermanager/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font>
</form>
</td></tr>
</table>
</center>
</body>
</html>
Form 2
<?php session_start(); ?>
<html>
<head>
<title>request form</title>
<style>p{font:10pt arial;}</style>
</head>
<body>
<form action="contact_me/process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name=name size=25>
</td>
</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=from size=25 maxlength=25>
</td>
</tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<textarea cols=50 name=message rows=7></textarea>
<p align=center>
<input type=submit value="Send Message">
<input type=reset value=Reset name="reset">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
ass you can see from the code I was going to use sessions. But not to familiar with it even though I have experience with php I am still quite new to it and need help. I want to pars form data to both forms. and the product name to form two. any help on this would be greatly appreciated.. I hope this is clear enough for some one out there to help.....
Ok New code Three forms 1.main form submits information to form1 and form2.
I have set up using a session so I have: session.php
<?php
session_start();
// store session data
$_SESSION['af_first_name'] = $af_first_name;
$_SESSION['af_last_name'] = $af_last_name;
$_SESSION['af_email'] = $af_email;
$_SESSION['cf_address'] = $cf_item_name;
?>
That handles variables.
My new code for index.php
<?php
// including the session file
require_once("session_start.php")
?>
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
?>
</head>
<body>
<h2>Winner Aution Item Request Form</h2>
<p><span class="error"><FONT><font color="red">* required field.</font></span></p>
<form name="form1">
First Name: <input type="text" name="$af_first_name" id="af_first_name" value="<?php if(isset($_SESSION['af_first_name'])){echo stripslashes($_SESSION['af_first_name']); unset($_SESSION['af_first_name']); } ?>" /><br>
Last Name: <input type="text" name="$af_last_name" id="af_last_name" value="<?php if(isset($_SESSION['af_last_name'])){echo stripslashes($_SESSION['af_last_name']); unset($_SESSION['af_last_name']); } ?>" /><br>
E-Mail: <input type="text" name="$af_email" id="af_email" value="<?php if(isset($_SESSION['af_email'])){echo stripslashes($_SESSION['af_email']); unset($_SESSION['af_email']); } ?>" /><br>
</form>
<form name="form2">Copy and Paste Auction Name Below!<br>
Product Name <br><input type="text" name="$cf_item_name" id="cf_item_name" value="<?php if(isset($_SESSION['cf_item_name'])){echo stripslashes($_SESSION['cf_item_name']); unset($_SESSION['cf_item_name']); } ?>" /><br>
<input type="Submit" value="Submit" name="submit" onsubmit="form2.submit(); form3.submit();"></input>
That form takes input and sets to session. Session.php picks it up and places it in variable form. From here I used a strip for the underscores. and when it goes to form1 and form2 varables pick it up and fill in the form. Here is my new form1
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<center>
<table cellspacing="10" bgcolor="#CCCCCC" style="border: 0px solid #000000;"> <tr><td>
<form action="http://newsletter.jeremyahenry.com//s.php" method=GET>
<strong><font color="#660000">Your First Name:</font></strong>
<input type="text" id="$af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" name="f" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#660000">Your Last name:</font></strong>
<input type="text" id="$af_last_name" value="<?php echo (!empty($_SESSION['_af']['af_last_name'])?$_SESSION['_af']['af_last_name']:'') ?>" name="l" style="background-color : #FFFFFF" size=11 maxlength=40><br>
<strong><font color="#000066">Email address:</font></strong><br>
<input type="text" id="$af_email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" name="e" style="background-color : #FFFFFF" size=20 maxlength=50>
<input type="image" src="http://newsletter.jeremyahenry.com/images/go-button.gif" name="submit" value="Submit"><br>
<input type="hidden" name="r" value="4">
<input type="hidden" name="a" value="sub">
<input type="hidden" name="ref" value="none">
<br>
<font color="#003300">HTML: <input type="RADIO" name="h" value="1">Yes
<input type="RADIO" name="h" value="0" checked="checked">No<br>
</font></form>
</td></tr></table>
</center>
<?php
if(!empty($_SESSION['_mf'])):
unset($_SESSION['_mf']);
endif;
?>
form2:
<?php
function stripZlashes($string)
{
//This function is to strip slashes for either array or a String
if (!is_array($string)) return stripslashes($string);
$nvar = array();
foreach ($string as $key => $value)
$nvar[stripslashes($key)] = stripZlashes($value);
return $nvar;
}
if(!empty($_SESSION['_mf'])): //Strip all possible back slashes
stripZlashes($_SESSION['_mf']);
endif;
// including the session file
require_once("session_start.php")
?>
<form action="process.php" method=post>
<table align=left border=0 height=300>
<tr>
<td nowrap>
<p> Your name:
<input maxlength=25 name="af first name" id="af_first_name" value="<?php echo (!empty($_SESSION['_af']['af_first_name'])?$_SESSION['_af']['af_first_name']:'') ?>" size=25> />
</td</tr>
<tr>
<td nowrap>
<p> Your email:
<input name=af email id="af email" value="<?php echo (!empty($_SESSION['_af']['af_email'])?$_SESSION['_af']['af_email']:'') ?>" size=25 maxlength=25> />
</td></tr>
<tr>
<td colspan=2>
<center>
<p align=center>Enter your Auction item Name below:
<br>
<input name="cf item name" id="cf item name" value="<?php echo (!empty($_SESSION['_cf']['cf_item_name'])?$_SESSION['_cf']['cf_item_name']:'') ?>" rows="1" />
<p align=center>
<input type=submit value="Send Message">
</td></tr></table>
</form>
</center>
Ok now i have an issue with it submitting correctly...
<form name="form1">
<input type="text" value="" name="somename" onkeyup="form2.somename.value=this.value" />
</form>
<form name="form2">
<input type="text" value="" name="somename" />
</form>
check out the above code. hope this could be helpful. Or if this is not the result which you require. so you can be brief with your requirements in reply.
I don't know the usage or need of your implementation: maybe it is like a 3 step registration form?
It could be done in different ways without complicating it too much.
You could put all three forms in the same page and only showing the right one
according to th data being posted to the same page. It is the old way of doing things.
With Ajax calls, templates and javascript it could be don simpler but it depends on
your experience.
on each element you can mention as per their relevent events, such as
Ex. onkeyup="form2.elementname.value=this.value"
Just some background. I'm using an MVC. My form is put in a div in my template. It posts to the same page where my controller catches it with an isset(), saves stuff to the database, and redirects to a welcome page.
EDIT: It posts everything like it should if I remove the action part of the form. Must be something pertaining to the way index.php reroutes it to ensure that the user has permission to go to that URL, etc. Still looking for a solution.
I've done some debugging and it is apparent that the variables are not showing up in the $_POST variable.
<form method="post" action="<?php echo BASE_URL; ?>/login/register">
<fieldset><legend>Person Info</legend>
<table>
<tr><td><label for="firstname" class="required">Firstname:</label></td>
<td><input name="firstname" id="firstname" type="text" value="<?php echo $firstname; ?>" /></td>
</tr>
<tr><td><label for="lastname" class="required">Lastname:</label></td>
<td><input name="lastname" id="lastname" type="text" value="<?php echo $lastname; ?>" /></td>
</tr>
<tr><td><label for="email">Email:</label></td>
<td><input name="email" id="email" type="text" value="<?php echo $email; ?>" /></td>
</tr>
<tr><td><label for="username" class="required">Username: </label></td>
<td><input name="username" id="username" type="text" value="<?php echo $username; ?>" /></td>
</tr>
<tr><td><label for="password" class="required">Password:</label></td>
<td><input name="password" id="password" type="password" value="<?php echo $password; ?>" /></td>
</tr>
<tr><td><label for="pass2" class="required">Confirm:</label></td>
<td><input name="pass2" id="pass2" type="password" value="<?php echo $pass2; ?>" /></td>
</tr>
</table>
<button type="submit" class="btn btn-custom-lighten">Submit</button>
<button type="button" class="btn"
onClick="parent.location='<?php echo BASE_URL; ?>/nonprofit/welcome'">
Cancel
</button>
<br>
<br>
<button type="button" class="btn btn-primary"
onClick="parent.location='<?php echo BASE_URL; ?>/nonprofits/register'">
Nonprofits Register Form
</button>
<br>
</fieldset>
</form>
You can see my names are consistent from the controller code.
public function register()
{
print_r($_POST);
if (isset($_POST['firstname'])) {
try {
$person = new Person();
$person->handleUpdate($_POST);
$person->setUsername($_POST['username']);
$person->setPassword($_POST['password']);
$person->save();
header('Location: '.BASE_URL.'/login/welcome');
exit();
}
catch (Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
$this->template->blocks['content'][] = new Block('registerForm.inc',array('return_url'=>$this->return_url));
}
Any help would be appreciated, but it looks to be an issue with my form. My form does get rendered, it just doesn't submit.