Assuming a situation like this, a page with simple form input phone number and it allow multi user - access:
<form>
Name: * <input type="text" name="name" /><br />
Phone: (if any) <input type="text" name="phone" /><br />
</form>
The phone field in database is pre-defined as allow-null.
The problem is when user A inputting the form , user B modify the database and set phone field as not-null . When user A submit , the phone will be a null value and post to the mysql database.
What i want to achieve is , if that field is modifyied to non-null, it should refresh before submit, retrieve the database structure before submit. Once there is difference, it return to the form and display like the following
<form>
Name: * <input type="text" name="name" /><br />
Phone: * <input type="text" name="phone" /> Sorry. You have to enter phone number<br />
</form>
How can it implement base on php(if possible)/ ajax? Thanks for the help.
Its quite weird to implement any refresh before submit and make decisions on browser side.
Such a situation should be checked on PHP side (after submit), which should return an error result-code meaning "The field is not null any more, please provide a value"
Related
Kind of an odd question and kinda hard to explain so will try my best.
I am wondering if it is possible to take the following:
<label for="page_name">page name</label><br>
<input type="text" name="page_name" maxlength="50" size="30">
and Display none; in the CSS so that this field isn't visible to anyone filling our the form, so that its left blank. Well not blank I would like to have a preset value so that when the form is filled out, I get all their entered details and I get my preset field "page_name" that has text I have entered so that I can put for example "page 5" so that I can see which page the form has been filled out on.
Is it possible to do it in html? I have done in the past by making each page have its own form and this time around I feel like there must be an easier solution?
Thanks in advance!
Simple use type="hidden" value="your value"
<input type="text" type="hidden" value="your value" name="page_name" maxlength="50" size="30">
and submit this input field with other all fields
This is very possible, I used it to track IP adresses once.
You can simply set the value by hand:
<input type="text" name="page_name" value="Default input value" style="display:none;">
Make sure you set it to display:none; (this can be done from your stylesheet too).
Set the value="default value" wich is what otherwise would be entered by the user.
Example:
function showvalue(){
alert($('input').attr('value'));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="page_name" value="Default input value" style="display:none;">
<button onclick="showvalue()">Show value </button>
I am attemping to create a PHP login system using MySQLi.
However I have created an HTML Form:
<form action="register_manager.php" method="post">
<p>Please fill all fields!</p>
<input type="text" name="username" value="<?PHP print $getuser; ?>" maxlength="15" /><br />
<input type="password" name="password" placeholder="Password" maxlength="15" />
<input type="password" name="confirmpassword" placeholder="Confirm Password" /><br />
<input type="text" name="email" placeholder="E-Mail Address" />
<p style="margin: 0; padding: 0;">
(Use a vaid a valid E-Mail Address for activation!)
</p>
<p>
Already got an account?
</p>
<input type="submit" name="regsubmit" value="Register"/><br />
<?PHP echo '<p>'.$errormsg.'</p>'; ?>
</form>
Once I click submit, it redirects me to the registration_manager.php page, which is not what I want it to do. I am new to PHP so I am not aware on why it is doing this, instead of registering the user.
This is the register_manager.php file:
http://pastebin.com/cvbA6L6P
The action specified in your form is register_manager.php so whenever you hit the submit button you will get redirected there. Also, in the link you provided of the source code of register_manager.php, you're generating error messages, depending on the case, but never printing them on the page so the user can see what is wrong, unless of course the html form you provided is included in the register_manager.php. Finally, when testing make sure you fill all the requirements set by the if statements in you register_manager.php file, i.e. pass all wanted fields (username, email (which must be longer than 7 chars, containing the '#' and '.' characters), password, password confirmation). Hope this solves your question!
What you are describing is normal. The browser will send a POST request to the URL defined as action. So you need to render the form there as well. You can either abstract the form out and reuse it in both files or do the initial form rendering and the processing in one file by checking if $_POST['regsubmit'] is set (if it is not set you are rendering the form initially).
Submit button will activate the request of the webpage specified in the attribute action, passing the information inside the form by the method selected. In your example, the information is passed to register_manager.php using POST method.
To retrieve the information passed, you could use the arrays $_POST and $_GET depending the method used. In your example:
<?php
print $_POST['password'];
print $_POST['confirmpassword'];
print $_POST['email'];
?>
My client is using interspire email marketer, which generate html form, and save all data into crm database.
In the form, there is a postcode area, my client wants to send email alert to different department based on this postcode.
I am thinking to create a seperate php file to match the postcode and send email alert.
But there is already a form.php in action. How can I add another action? Or is there any better way to achieve this?
Many Many thanks.
Below is the form code:
<form name="ppt_form" class="ppt-form" method="post" action="http://na03.mypinpointe.com/form.php?form=332" id="frmSS332">
<p><span class="required">*</span>Your Email Address:<br />
<input type="text" class="email" name="email" fid="e" fname="Email" ftype="Email" reqd="1"/></p>
<p>Phone:<br />
<input type="text" name="CustomFields[8]" id="CustomFields_8_332" value="" fid="8" fname="Phone" size='50'></p>
<p>Postal: <br />
<input type="text" name="CustomFields[20]" id="CustomFields_20_332" value="" fid="20" fname="Postal" size='50'></p>
<p><input type="button" class="update-button" value="Submit"/></p>
</form>
Eventually I leave the form with 1 action.
and add a ajax on button click.
I am trying to submit three forms in single page. But I stuck at one point.
I want to make verification of mobile Number in first Form. then use that Mobile Number in final Form submission
I have tried using this in single Form but then How can I send web request for sending verification pin with verify Mobile Button.
I have Three forms like this,
//First Form Take Mobile Number, web service will send verification Pin as reply to this action
<form name="PhoneVerification" action="url to phone verification web service" >
Phone Number: <input type="text" name ="number" id="phone">
<input type="submit" name ="submit1" id="submit1">Verify Mibile Number</input>
</form>
//Second Form verifies pin Locally which is sent by first service
<form name="PinVerification" action="verify pin came from previous web service">
Verification Pin(Sent on Mobile Number): <input type="text" name ="pin" id="pin">
<input type="submit" name ="submit2" id="submit2">Verify Pin</input>
</form>
//Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
<form action="web service call to complete signup">
Email: <input type="text" name ="email" id="email">
Password: <input type="text" name ="pass" id="pass">
PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
<input type="submit" name ="submit3" id="submit3">Complete Signup</input>
</form>
The Problem is I am not able to get value of phone number as page is refreshed after that Form submission.
I read some threads about using AJAX , But How can I use Ajax in this type Of situation.
How can I achieve this. with AJAX, or using PHP.
Id must be unique in your html page. In above code id="phone" be present in first to forms. the second form in pinVerfication right but there is an same id = "phone" . please change it and make an another try. third form have also same problem
//Second Form verifies pin Locally which is sent by first service
<form name="PinVerification" action="verify pin">
Verification Pin(Sent on Mobile Number): <input type="text" name ="number" id="pin">
<input type="submit" name ="submit2" id="submit2">Verify Pin</input>
</form>
/Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
<form action="web service call to complete signup">
Email: <input type="text" name ="email" id="email">
Password: <input type="text" name ="pass" id="pass">
PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
<input type="submit" name ="submit3" id="submit3">Complete Signup</input>
</form>
You can use cookies or sessions to achieve this task.
if you want to do it with only javascript, you can use cookies. you can get the best reference from w3schools
You can do it with server side script like php and use ajax.
In this case you can use session.
First form submission store number in cookies or session. and in another form you get that value from cookie or session and make use of it.
Note: Don't forgot to delete cookies or session after you finish all work.
I have mysql table members with columns id, user, password, and verified
When a user logs in, using user and password (compared against members-db) they are presented with a form. The form gathers info to be manually checked by an admin.
Upon submitting the form, it will send an email to admin with all the details to manually confirm.
The problem that I am hitting is that admin wants the email to contain a link that will enable him to update the verified field in members table upon clicking. I need to send a previously stored variable with the form to do so. That way I have a link to the members table.
For example, If I store $user_id as the id of whichever row I need to update, and I could send it forward with the form, then I could just use the UPDATE feature WHERE id = $user_id
Here is my form ...
<form method="post" name="verify_form" action="../includes/verify.php">
Website for Online Verification: <input type="text" name="webpage" id="webpage" /><br />
Identification Number: <input type="text" name="number" id="number" /><br />
Expiration Date: <input type="text" name="expire" id="expire" /><br />
<input type="submit" value="Verify Me!" onclick="return vformhash(this.form, this.form.webpage, this.form.number, this.form.expire);" />
<input type="reset" value="Clear Form" />
</form>
Is there a way to send my previously captured $user_id to the verify.php page when user submits?
You could use a hidden field:
<input type="hidden" name="userid" value="<?php echo $user_id; ?>" >
You can use:
<input type='hidden' name='user' value=<?php echo $user_id; ?>>
inside the form.
You could send it in url like
$url = "verify.php?user_id=" . $ user_id;
And access it in verify.php page by
$ user_id = $_GET ['user_id'];
You can use hidden fields: <input type="hidden"....
If the information is sensitive, you should not put it in those hidden fields, but rather store it in the session or otherwise on your server. You can then use a hidden field to store a key that you can use to find those values again later.
If you would use regular session variables, without a key in the form, you might get the issue of finding the wrong value if the user has multiple forms open in multiple tabs.
Two options:
Change your for tag to pass the ID as a GET param :
action="../includes/verify.php?user_id=123"
-or-
Add a hidden field :
<input type="hidden" name="user_id" id="user_id" value="123" />
You will be able to access this value with either $_GET['user_id'] for option #1, or $_POST['user_id'] for option #2 within your PHP script.
When the user logs in, save their ID in a session value such as $_SESSION["userID"]. Then in verify.php you can access $_SESSION["userID"]. It's cleaner than passing the ID back and forth as parameters.