?
Solved

Custom submit form button, PHP

Posted on 2011-10-25
9
Medium Priority
?
516 Views
Last Modified: 2012-05-12
Using an online webcart to process payments for a client.  He wants his clients to be able to enter a customized dollar amount to be submitted to the cart.  This works fine with the default buttons.  If I change the default button to the "buy now" image on the rest of the site, the cart doesn't receive the input and advises "your cart is empty" upon entering your dollar value and hitting "buy now".

I'm sure its something silly in the form code.  Here is the code in question, with the URL obscured in the form method line:

<form method="post" action="http://www.shoppingcart.com/xxxxx/cart">
<input type="hidden" name="name2" value="Payment[#OMITSHIP#]" />
<input type="hidden" name="description2" value="Payment" />
<strong> Enter Custom Payment Amount: $</strong>
<input name="price2" size="6" maxlength="8" />
<input type="image" src="/images/e-store_images/buy_now_5.jpg" value="Submit" alt="Submit" width="93" height="16"/>
</form>

Tips appreciated.
0
Comment
Question by:mikeshaver
  • 5
  • 4
9 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37029294
You have to give to your input image the name 'submit'

<input type="image" src="/images/e-store_images/buy_now_5.jpg" value="Submit" name='Submit' alt="Submit" width="93" height="16"/>

Ithink it should all in lowercase: check if the original code uses capitalized or not capitalized : submit vs Submit

Cheers
0
 
LVL 1

Author Comment

by:mikeshaver
ID: 37029301
Still getting "your cart is empty"  Code is now this:

<form method="post" action="http://www.shoppingcart.com/xxxxx/cart">
<input type="hidden" name="name2" value="Payment[#OMITSHIP#]" />
<input type="hidden" name="description2" value="Payment" />
<strong> Enter Custom Payment Amount: $</strong>
<input name="price2" size="6" maxlength="8" />
<input type="image" src="/images/e-store_images/buy_now_5.jpg" value="Submit" name='Submit' alt="Submit" width="93" height="16"/>
</form>
0
 
LVL 1

Author Comment

by:mikeshaver
ID: 37029306
And tried lowercase like this:

<form method="post" action="http://www.shoppingcart.com/xxxxx/cart">
<input type="hidden" name="name2" value="Payment[#OMITSHIP#]" />
<input type="hidden" name="description2" value="Payment" />
<strong> Enter Custom Payment Amount: $</strong>
<input name="price2" size="6" maxlength="8" />
<input type="image" src="/images/e-store_images/buy_now_5.jpg" value="submit" name='submit' alt="submit" width="93" height="16"/>
</form>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37029327
Sorry, I forgot to say to delete value tag: it doesn't exists for img tag. I don't know if this can raise an error, but try deleting it.

If you use Firefox, install Firebug and use it to debug your code.

I also suggest to put at the top of your script these lines:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

This way you'll be sure every problem will be noticed to you. Remember to comment or delete these lines in your production environment.

I assume you're absolutely sure to not have any typo in your action value and other relevant values of your form.

Cheers

 
0
 
LVL 1

Author Comment

by:mikeshaver
ID: 37029342
No joy.  Not sure on the typos...I'm not much of a coder...I'm actually thinking that one of the "names" or "types" is wrong, and thus undefined so no values are returned.

This is the code as it stands now, not working (cart says its empty):

<form method="post" action="http://www.shoppingcart.com/xxxxx/cart">
<input type="hidden" name="name2" value="Payment[#OMITSHIP#]" />
<input type="hidden" name="description2" value="Payment" />
<strong> Enter Custom Payment Amount: $</strong>
<input name="price2" size="6" maxlength="8" />
<input type="image" src="/images/e-store_images/buy_now_5.jpg" name='submit' alt="submit" width="93" height="16"/>
</form>

This code, shows the "default" buy now button, and works correctly but the goal is to get the custom button from the image at /images/e-store_images/buy_now_5.jpg

<form method="post" action="http://www.shoppingcart.com/xxxxx/cart">
<input type="hidden" name="name2" value="Payment[#OMITSHIP#]" />
<input type="hidden" name="description2" value="Payment" />
<strong> Enter Custom Payment Amount: $</strong>
<input name="price2" size="6" maxlength="8" />
<input type="submit" name="add2" value="Buy now" />
</form>
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 37029466
Look at original code: as you see, the input type='submit' has the name='add2'. This means that the receiving script has code like this

if (isset($_POST['add2')){
//add to cart
}

Since in your modified code the name is 'submit' the script doesn't work so change the name of your image from 'submit' to 'add2' (I suggested to use 'submit' because in the code you originally posted you used 'Submit'

<form method="post" action="http://www.shoppingcart.com/xxxxx/cart">
<input type="hidden" name="name2" value="Payment[#OMITSHIP#]" />
<input type="hidden" name="description2" value="Payment" />
<strong> Enter Custom Payment Amount: $</strong>
<input name="price2" size="6" maxlength="8" />
<input type="image" src="/images/e-store_images/buy_now_5.jpg" name='add2' alt="submit" width="93" height="16"/>
</form>

You'll see that this way it will work

Cheers
0
 
LVL 1

Author Comment

by:mikeshaver
ID: 37029505
Shazam!  :)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37029508
Lol! What is 'Shazam'?
I suggest you a very good book about how php and mysql work together in a web site building: http://www.sitepoint.com/books/phpmysql4/

Good luck with your project.
0
 
LVL 1

Author Comment

by:mikeshaver
ID: 37029510
Shazam is "joy"  :)  Thanks for your help tonight.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question